<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>社交网站 - 顶部导航栏</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        :root {
            --primary: #4f46e5;
            --primary-light: #f0f9ff;
            --primary-dark: #4338ca;
            --secondary: #64748b;
            --light-bg: #f8fafc;
            --border-color: #e2e8f0;
            --shadow: 0 4px 6px rgba(0,0,0,0.05);
            --transition: all 0.3s ease;
        }
        
        body {
            font-family: 'Inter', system-ui, -apple-system, sans-serif;
            margin: 0;
            padding: 0;
        }
        
        /* 导航栏基础样式 */
        .site-navbar {
            background-color: white;
            box-shadow: var(--shadow);
            padding: 0.75rem 0;
            position: sticky;
            top: 0;
            z-index: 1000;
        }
        
        .navbar-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 1rem;
        }
        
        /* 左侧Logo和导航 */
        .navbar-left {
            display: flex;
            align-items: center;
        }
        
        .site-logo {
            display: flex;
            align-items: center;
            text-decoration: none;
            margin-right: 2rem;
        }
        
        .logo-icon {
            color: var(--primary);
            font-size: 1.8rem;
            margin-right: 8px;
        }
        
        .logo-text {
            font-size: 1.25rem;
            font-weight: 700;
            color: #1e293b;
        }
        
        .main-nav {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }
        
        .nav-item {
            margin-right: 1.5rem;
        }
        
        .nav-link {
            text-decoration: none;
            color: var(--secondary);
            font-weight: 500;
            transition: var(--transition);
            padding: 5px 0;
            position: relative;
        }
        
        .nav-link:hover, .nav-link.active {
            color: var(--primary);
        }
        
        .nav-link.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 3px;
            background-color: var(--primary);
            border-radius: 3px;
        }
        
        /* 中间搜索框 */
        .navbar-middle {
            flex: 1;
            max-width: 600px;
            margin: 0 1rem;
            position: relative;
        }
        
        .search-box {
            width: 100%;
            padding: 10px 15px 10px 40px;
            border: 1px solid var(--border-color);
            border-radius: 24px;
            font-size: 0.95rem;
            transition: var(--transition);
        }
        
        .search-box:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
        }
        
        .search-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--secondary);
        }
        
        /* 搜索联想下拉框 */
        .search-suggestions {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background-color: white;
            border-radius: 0 0 12px 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            margin-top: 5px;
            z-index: 100;
            display: none;
        }
        
        .search-suggestions.active {
            display: block;
        }
        
        .suggestion-item {
            padding: 10px 15px;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }
        
        .suggestion-item:hover {
            background-color: var(--primary-light);
        }
        
        .suggestion-icon {
            margin-right: 10px;
            color: var(--secondary);
            font-size: 0.9rem;
        }
        
        /* 右侧用户区域 */
        .navbar-right {
            display: flex;
            align-items: center;
        }
        
        .auth-buttons {
            display: flex;
            gap: 10px;
        }
        
        .login-btn, .register-btn {
            padding: 8px 16px;
            border-radius: 20px;
            font-weight: 500;
            transition: var(--transition);
            font-size: 0.9rem;
        }
        
        .login-btn {
            background: none;
            border: 1px solid var(--primary);
            color: var(--primary);
        }
        
        .login-btn:hover {
            background-color: var(--primary-light);
        }
        
        .register-btn {
            background-color: var(--primary);
            border: 1px solid var(--primary);
            color: white;
        }
        
        .register-btn:hover {
            background-color: var(--primary-dark);
        }
        
        /* 用户头像下拉菜单 */
        .user-menu {
            position: relative;
            margin-left: 1rem;
        }
        
        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
            cursor: pointer;
            border: 2px solid transparent;
            transition: var(--transition);
        }
        
        .user-avatar:hover {
            border-color: var(--primary);
        }
        
        .dropdown-menu {
            position: absolute;
            top: 100%;
            right: 0;
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            min-width: 200px;
            margin-top: 8px;
            z-index: 100;
            display: none;
            overflow: hidden;
        }
        
        .dropdown-menu.active {
            display: block;
            animation: fadeIn 0.2s ease forwards;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .dropdown-item {
            padding: 12px 15px;
            display: flex;
            align-items: center;
            text-decoration: none;
            color: #1e293b;
            transition: var(--transition);
        }
        
        .dropdown-item:hover {
            background-color: var(--primary-light);
            color: var(--primary);
        }
        
        .dropdown-item i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
        }
        
        .dropdown-divider {
            height: 1px;
            background-color: var(--border-color);
            margin: 5px 0;
        }
        
        /* 汉堡菜单按钮 */
        .hamburger-btn {
            display: none;
            background: none;
            border: none;
            font-size: 1.5rem;
            color: var(--secondary);
            cursor: pointer;
            transition: var(--transition);
        }
        
        .hamburger-btn:hover {
            color: var(--primary);
        }
        
        /* 移动端侧边导航 */
        .mobile-nav {
            position: fixed;
            top: 0;
            left: -300px;
            width: 280px;
            height: 100vh;
            background-color: white;
            box-shadow: 2px 0 10px rgba(0,0,0,0.1);
            z-index: 2000;
            transition: var(--transition);
            padding: 1.5rem 1rem;
            overflow-y: auto;
        }
        
        .mobile-nav.active {
            left: 0;
        }
        
        .mobile-nav-header {
            display: flex;
            align-items: center;
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid var(--border-color);
        }
        
        .close-nav {
            background: none;
            border: none;
            font-size: 1.5rem;
            color: var(--secondary);
            cursor: pointer;
            margin-right: 1rem;
        }
        
        .mobile-main-nav {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .mobile-nav-item {
            margin-bottom: 0.5rem;
        }
        
        .mobile-nav-link {
            display: block;
            padding: 12px 15px;
            text-decoration: none;
            color: #1e293b;
            border-radius: 8px;
            transition: var(--transition);
        }
        
        .mobile-nav-link:hover, .mobile-nav-link.active {
            background-color: var(--primary-light);
            color: var(--primary);
        }
        
        /* 遮罩层 */
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0,0,0,0.5);
            z-index: 1500;
            display: none;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .overlay.active {
            display: block;
            opacity: 1;
        }
        
        /* 响应式设计 */
        @media (max-width: 992px) {
            .main-nav {
                display: none;
            }
            
            .hamburger-btn {
                display: block;
                margin-right: 1rem;
            }
            
            .navbar-middle {
                max-width: 400px;
            }
        }
        
        @media (max-width: 768px) {
            .navbar-middle {
                max-width: none;
                margin: 0 0.5rem;
            }
            
            .auth-buttons {
                gap: 5px;
            }
            
            .login-btn, .register-btn {
                padding: 6px 12px;
                font-size: 0.85rem;
            }
        }
        
        @media (max-width: 576px) {
            .navbar-middle {
                display: none;
            }
            
            .mobile-search {
                margin: 1rem 0;
                position: relative;
            }
            
            .mobile-search-box {
                width: 100%;
                padding: 10px 15px 10px 40px;
                border: 1px solid var(--border-color);
                border-radius: 24px;
                font-size: 0.95rem;
            }
            
            .mobile-search-icon {
                position: absolute;
                left: 15px;
                top: 50%;
                transform: translateY(-50%);
                color: var(--secondary);
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <header class="site-navbar">
        <div class="navbar-container">
            <!-- 左侧：Logo和主导航 -->
            <div class="navbar-left">
                <button class="hamburger-btn">
                    <i class="fas fa-bars"></i>
                </button>
                
                <a href="#" class="site-logo">
                    <i class="fas fa-connectdevelop logo-icon"></i>
                    <span class="logo-text">社交圈</span>
                </a>
                
                <ul class="main-nav">
                    <li class="nav-item">
                        <a href="#" class="nav-link active">首页</a>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">文章</a>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">问答</a>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">活动</a>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="nav-link">商品</a>
                    </li>
                </ul>
            </div>
            
            <!-- 中间：搜索框 -->
            <div class="navbar-middle">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-box" placeholder="搜索内容、用户、话题...">
                
                <!-- 搜索联想下拉框 -->
                <div class="search-suggestions">
                    <div class="suggestion-item">
                        <i class="fas fa-user suggestion-icon"></i>
                        <span>张明</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-file-alt suggestion-icon"></i>
                        <span>前端开发最佳实践</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-hashtag suggestion-icon"></i>
                        <span>科技新闻</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-question-circle suggestion-icon"></i>
                        <span>如何提高编程效率？</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-calendar suggestion-icon"></i>
                        <span>2023开发者大会</span>
                    </div>
                </div>
            </div>
            
            <!-- 右侧：用户入口 -->
            <div class="navbar-right">
                <!-- 未登录状态 -->
                <div class="auth-buttons">
                    <button class="login-btn">登录</button>
                    <button class="register-btn">注册</button>
                </div>
                
                <!-- 已登录状态（默认隐藏） -->
                <div class="user-menu" style="display: none;">
                    <img src="https://picsum.photos/id/64/200/200" alt="用户头像" class="user-avatar">
                    
                    <!-- 下拉菜单 -->
                    <div class="dropdown-menu">
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-user"></i>
                            <span>个人中心</span>
                        </a>
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-bell"></i>
                            <span>消息通知</span>
                        </a>
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-cog"></i>
                            <span>设置</span>
                        </a>
                        <div class="dropdown-divider"></div>
                        <a href="#" class="dropdown-item">
                            <i class="fas fa-sign-out-alt"></i>
                            <span>退出登录</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </header>
    
    <!-- 移动端侧边导航 -->
    <div class="mobile-nav">
        <div class="mobile-nav-header">
            <button class="close-nav">
                <i class="fas fa-times"></i>
            </button>
            <a href="#" class="site-logo">
                <i class="fas fa-connectdevelop logo-icon"></i>
                <span class="logo-text">社交圈</span>
            </a>
        </div>
        
        <!-- 移动端搜索框 -->
        <div class="mobile-search">
            <i class="fas fa-search mobile-search-icon"></i>
            <input type="text" class="mobile-search-box" placeholder="搜索内容、用户、话题...">
        </div>
        
        <ul class="mobile-main-nav">
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link active">
                    <i class="fas fa-home me-3"></i> 首页
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-file-alt me-3"></i> 文章
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-question-circle me-3"></i> 问答
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-calendar-alt me-3"></i> 活动
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-shopping-bag me-3"></i> 商品
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-user me-3"></i> 个人中心
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-bell me-3"></i> 消息通知
                </a>
            </li>
            <li class="mobile-nav-item">
                <a href="#" class="mobile-nav-link">
                    <i class="fas fa-cog me-3"></i> 设置
                </a>
            </li>
        </ul>
    </div>
    
    <!-- 遮罩层 -->
    <div class="overlay"></div>
    
    <!-- 页面内容（仅用于演示） -->
    <div style="height: 2000px; padding: 2rem;">
        <h1>页面内容区域</h1>
        <p>滚动页面查看导航栏固定效果...</p>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 搜索框联想功能
            const searchBox = document.querySelector('.search-box');
            const suggestions = document.querySelector('.search-suggestions');
            
            searchBox.addEventListener('focus', function() {
                suggestions.classList.add('active');
            });
            
            searchBox.addEventListener('input', function() {
                if (this.value.length > 0) {
                    suggestions.classList.add('active');
                    // 这里可以添加AJAX请求获取实时搜索建议
                } else {
                    suggestions.classList.remove('active');
                }
            });
            
            document.addEventListener('click', function(e) {
                if (!searchBox.contains(e.target) && !suggestions.contains(e.target)) {
                    suggestions.classList.remove('active');
                }
            });
            
            // 选择搜索建议
            const suggestionItems = document.querySelectorAll('.suggestion-item');
            suggestionItems.forEach(item => {
                item.addEventListener('click', function() {
                    searchBox.value = this.querySelector('span').textContent;
                    suggestions.classList.remove('active');
                });
            });
            
            // 用户下拉菜单
            const userAvatar = document.querySelector('.user-avatar');
            const dropdownMenu = document.querySelector('.dropdown-menu');
            
            if (userAvatar) {
                userAvatar.addEventListener('click', function(e) {
                    e.stopPropagation();
                    dropdownMenu.classList.toggle('active');
                });
            }
            
            document.addEventListener('click', function() {
                if (dropdownMenu && dropdownMenu.classList.contains('active')) {
                    dropdownMenu.classList.remove('active');
                }
            });
            
            // 移动端导航
            const hamburgerBtn = document.querySelector('.hamburger-btn');
            const closeNavBtn = document.querySelector('.close-nav');
            const mobileNav = document.querySelector('.mobile-nav');
            const overlay = document.querySelector('.overlay');
            
            hamburgerBtn.addEventListener('click', function() {
                mobileNav.classList.add('active');
                overlay.classList.add('active');
                document.body.style.overflow = 'hidden'; // 防止背景滚动
            });
            
            function closeMobileNav() {
                mobileNav.classList.remove('active');
                overlay.classList.remove('active');
                document.body.style.overflow = ''; // 恢复背景滚动
            }
            
            closeNavBtn.addEventListener('click', closeMobileNav);
            overlay.addEventListener('click', closeMobileNav);
            
            // 模拟登录状态切换（实际应用中根据登录状态动态显示）
            const loginBtn = document.querySelector('.login-btn');
            const authButtons = document.querySelector('.auth-buttons');
            const userMenu = document.querySelector('.user-menu');
            
            loginBtn.addEventListener('click', function() {
                authButtons.style.display = 'none';
                userMenu.style.display = 'block';
            });
            
            // 退出登录功能
            const logoutBtn = document.querySelector('.dropdown-item:last-child');
            if (logoutBtn) {
                logoutBtn.addEventListener('click', function(e) {
                    e.preventDefault();
                    userMenu.style.display = 'none';
                    authButtons.style.display = 'flex';
                    dropdownMenu.classList.remove('active');
                });
            }
            
            // 导航链接激活状态
            const navLinks = document.querySelectorAll('.nav-link, .mobile-nav-link');
            navLinks.forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    
                    // 移除所有激活状态
                    navLinks.forEach(l => l.classList.remove('active'));
                    
                    // 添加当前激活状态
                    this.classList.add('active');
                    
                    // 如果是移动端，点击后关闭导航
                    if (this.classList.contains('mobile-nav-link')) {
                        closeMobileNav();
                    }
                });
            });
        });
    </script>
</body>
</html>
    